package cn.virens.mybatis.mapper.example;

import cn.virens.common.exception.APIException;
import cn.virens.mybatis.mapper.example.base.AbstractExampleCriteriaCriterion;
import cn.virens.mybatis.mapper.example.util.Util;

@SuppressWarnings("serial")
public class ExampleJoin extends AbstractExampleCriteriaCriterion<ExampleCriteria> {
	private final String table;
	private final String type;

	public ExampleJoin(String type, String table) {
		super(false, null);

		this.table = table;
		this.type = type;
	}

	public String getTable() {
		return table;
	}

	public String getType() {
		return type;
	}

	protected ExampleCriteria addCriterion(boolean isOr, String condition) throws APIException {
		this.criterionList.add(new ExampleCriteria(isOr, condition));

		return null;
	}

	protected ExampleCriteria addCriterion(boolean isOr, String condition, Object value) throws APIException {
		if (condition != null && !condition.isEmpty() && value != null && Util.isNotEmpty(value)) {
			this.criterionList.add(new ExampleCriteria(isOr, condition, enumv(value)));
		}

		return null;
	}

	protected ExampleCriteria addCriterion(boolean isOr, String condition, Object value1, Object value2) throws APIException {
		this.criterionList.add(new ExampleCriteria(isOr, condition, value1, value2));

		return null;
	}

}
